/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mk_tools;

import java.awt.Canvas;
import java.awt.Graphics2D;
import java.awt.event.*;
import java.util.ArrayList;

/**
 *
 * @author Mikael Köhlmyr, 2009
 */
public class SlicerCanvas extends Canvas implements MouseListener, MouseMotionListener{
    Point uLeft = new Point(10, 30); // x,y
    Point lRight = new Point(90, 70); // x,y
    public Rectangle rect = new Rectangle(uLeft, lRight); //uLeft Lright
    
    public ArrayList<Rectangle> Rectangles = new ArrayList<Rectangle>();

    public int height;
    public int width;
    public SlicerCanvas(int width, int height){
        //setBackground(Color.black);
        this.width = width;
        this.height = height;
        addMouseMotionListener(this);
        addMouseListener(this);
        Rectangles.add(rect);
        graphics();
    }

    public void graphics(){
        Graphics2D g = (Graphics2D) this.getGraphics();       
        while(true){
            paintSquares(g);
        }
    }

    public void paintSquares(Graphics2D g){
        for(Rectangle r : Rectangles){
            r.paint(g);
        }
    }

    public boolean validPosition(Rectangle r){
        if((r.x >= 0 && r.x <= width) && (r.y > 0 && r.y <= height)){
            return true;
        }
        return false;
    }

    public void mouseClicked(MouseEvent e) {
        if(rect.inBounds(e.getX(), e.getY())){
            System.out.println("Selected");
        }
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
        if(rect.inBounds(e.getX(), e.getY())){
            System.out.println("Let's move");
        }
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseDragged(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}
